package com.ruoyi.result.patents.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.result.patents.domain.Patents;
import com.ruoyi.result.patents.domain.ResultPatents;
import com.ruoyi.result.patents.domain.dto.ResultPatentsDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 专利信息Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-14
 */
@Mapper
public interface ResultPatentsMapper
{
    /**
     * 查询专利信息
     *
     * @param id 专利信息主键
     * @return 专利信息
     */
    public ResultPatents selectResultPatentsById(Long id);

    /**
     * 查询专利信息列表
     *
     * @param resultPatents 专利信息
     * @return 专利信息集合
     */
    public List<ResultPatents> selectResultPatentsList(ResultPatentsDTO resultPatents);

    /**
     * 新增专利信息
     *
     * @param resultPatents 专利信息
     * @return 结果
     */
    public int insertResultPatents(ResultPatents resultPatents);

    /**
     * 修改专利信息
     *
     * @param resultPatents 专利信息
     * @return 结果
     */
    public int updateResultPatents(ResultPatents resultPatents);

    /**
     * 删除专利信息
     *
     * @param id 专利信息主键
     * @return 结果
     */
    public int deleteResultPatentsById(Long id);

    /**
     * 批量删除专利信息
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResultPatentsByIds(Long[] ids);

    Patents selectPatentsById(Long id);

    List<ResultPatents> selectResultPatentsByIds(Long[] ids);

    @Select("SELECT COUNT(*) FROM result_patents WHERE sync_status = '是' AND is_deleted = 0")
    long selectCount();

    @Select("SELECT YEAR(authorization_date) as year, COUNT(*) as count FROM result_patents " +
            "WHERE is_deleted = 0 AND authorization_date IS NOT NULL " +
            "GROUP BY YEAR(authorization_date) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYear();

    @Select("SELECT YEAR(authorization_date) as year, COUNT(*) as count FROM result_patents " +
            "WHERE is_deleted = 0 AND authorization_date IS NOT NULL AND user_id = #{userId} " +
            "GROUP BY YEAR(authorization_date) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYearAndUserId(@Param("userId") Long userId);

    List<ResultPatents> selectResultPatentsListByDept(ResultPatentsDTO resultPatents);
}
